package com.itheima.extendedHomework.test2;

import java.util.ArrayList;

/*
已知：有一对兔子，从出生后第3个月起每个月都生一对兔子，小兔子长到第三个
	月后每个月又生一对兔子，假如兔子都不死，问第二十个月的兔子对数为多少？
	请用递归思想实现代码。
 */
public class ImmortalRabbit {
    //static int sum = 1;
    //static int WEEK = 20;
    static int month = 0;

    public static void main(String[] args) {

        ArrayList<Integer> oRabbit = new ArrayList<>();
        ArrayList<Integer> newRabbit = new ArrayList<>();
        getNum(oRabbit,newRabbit,20,1);
        month = 0;
        System.out.println("----------------------------");

        ArrayList<Integer> oRabbit1 = new ArrayList<>();
        ArrayList<Integer> newRabbit1 = new ArrayList<>();
        getNum(oRabbit1,newRabbit1,30,1);
    }

    private static void getNum(ArrayList<Integer> oRabbit, ArrayList<Integer> newRabbit,int week,int sum) {
        //sum = 1;
        if (month<3-1){
            oRabbit.add(1);
            newRabbit.add(0);
        }else {
            oRabbit.add((oRabbit.get(month - 1)) + newRabbit.get(month - 2));
            newRabbit.add(oRabbit.get(month));
        }
        sum += newRabbit.get(month);
        System.out.println("老兔子：" + oRabbit.get(month) + "，新生兔：" + newRabbit.get(month) + ",总和:" + sum + "，月份：" + (month+1));
        if (month < week-1){
            month++;
            getNum(oRabbit,newRabbit,week,sum);
        }else {
            return;
        }
    }
}
